/*
 * @Author: sean_kei@163.com
 * @Date: 2021-06-08 15:07:22
 * @LastEditors: sean_kei@163.com
 * @LastEditTime: 2022-08-03 14:45:13
 */
package com.wxhandle.cleandemo;

import java.util.List;

import javax.transaction.Transactional;

import com.wxhandle.cleandemo.application.cache.SysRoleClaimCache;
import com.wxhandle.cleandemo.core.domain.identity.SysRole;
import com.wxhandle.cleandemo.core.services.SysRoleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
@Transactional
public class CleanApiStartup implements CommandLineRunner {

    @Autowired
    private SysRoleClaimCache cache;

    @Autowired
    private SysRoleService roleService;

    @Override
    public void run(String... args) throws Exception {

        List<SysRole> roles = roleService.getList(null);
        roles.forEach(role->{
            cache.add(role.getId(), role.getClaims().stream().map(c-> c.getId()).toArray(String[]::new));
        });
        // String name = user.getName();

        // System.out.println(name);
    }

}
